
//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
/** @author  John Miller
 *  @version 1.0
 *  @date    Tue Jan 29 19:06:48 EST 2013
 *  @see     LICENSE (MIT style license file).
 */

import java.io.File

//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
/** This object is used to build the scalation Scala-based Simulation System.
 *  Comment out lines using // for customized builds.  To build the complete
 *  scalation system, type the following two commands:
 *  > scalac Build.scala
 *  > scala Build
 *  Check the file called 'errorlog' for errors generated by any of the
 *  build functions.  Note, this Build object may be replaced with the
 *  Simple Build Tool (sbt) in the future. 
 */
object Build extends App
{
    private val base_dir   = ""
    private val source_dir = base_dir + "src"
    private val class_dir  = base_dir + "classes"
    private val doc_dir    = base_dir + "doc"
    private val ex_dir     = base_dir + "examples"

    private val sep = File.separator     // file separator ('/' for UNIX, '\' for Windows)

    /** The packages making up scalation -- comment out (//) for selective builds
     */
    private val packages = Array ("scalation" + sep + "util",
                                  "scalation" + sep + "math",
                                  "scalation" + sep + "linalgebra",
                                  "scalation" + sep + "linalgebra_gen",
                                  "scalation" + sep + "calculus",
                                  "scalation" + sep + "random",
                                  "scalation" + sep + "stat",
                                  "scalation" + sep + "scala2d",
                                  "scalation" + sep + "plot",
                                  "scalation",
                                  "scalation" + sep + "animation",
                                  "scalation" + sep + "minima",
                                  "scalation" + sep + "maxima",
                                  "scalation" + sep + "analytics",
                                  "scalation" + sep + "metamodel",
                                  "scalation" + sep + "queueingnet",
                                  "scalation" + sep + "dynamics",
                                  "scalation" + sep + "activity",
                                  "scalation" + sep + "event",
                                  "scalation" + sep + "process",
                                  "scalation" + sep + "state")

    /** The example simulation models -- comment out (//) for selective builds
     */
    private val examples = Array ("dynamics",
                                  "activity",
                                  "event",
                                  "montecarlo",
                                  "process",
                                  "state",
                                  "analytics",
                                  "simopt",
                                  "game")

    //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
    /** Compile the source files (.scala) for all the packages in scalation.
     */
    def compile
    {
        val c = new Comp (class_dir, class_dir)
        for (p <- packages) {
            val n = c.compPackage (source_dir + sep + p)
            println ("compiled package " + p + ": " + n + " files")
        } // for
    } // compile

    //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
    /** Compile the source files (.scala) for all the example models.
     */
    def compileEx
    {
        for (e <- examples) {
            val c = new Comp (class_dir, ex_dir + sep + e + sep + "classes")
            val n = c.compPackage (ex_dir + sep + e)
            println ("compiled example " + e + ": " + n + " files")
        } // for
    } // compileEx

   //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
    /** How to generate index.html files for browsing the source code.
     */
    def genIndexHtml
    {
        val command = "scala -cp " + class_dir + " scalation.util.GenIndexHtml"
        println ("To generate index.html files for browsing the source code execute:")
        println ("> " + command)
    } // genIndexHtml

    //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
    /** How to generate scaladoc files for all the scalation packages.
     *  @see http://www.scala-lang.org/docu/files/tools/scaladoc.html
     */
    def doc
    {
        val _J    = " -J-mx1024m"
        val _cp   = " -classpath " + ".." + sep + class_dir
        val files = " .." + sep + source_dir + sep + "scalation" + sep + "*" + sep + "*.scala"
        println ("To generate scaladoc documentation execute the following two commands:")
        println ("> " + "cd doc")
        println ("> " + "scaladoc" + _J + _cp + files)
    } // doc

    compile
    compileEx
    genIndexHtml
    doc

} // Build

